<%@page import="java.util.Collection"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>员工管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页></cite></a> <a><cite>员工管理></cite></a>
			<a href="EmpServlet"><cite>用户管理</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<xblock>
			<button class="layui-btn layui-btn-danger" onclick="delAll()">
				<i class="layui-icon">&#xe640;</i>批量删除
			</button>
			<button class="layui-btn" onclick="member_add('添加员工','EmpAdd.jsp','500','600')">
				<i class="layui-icon">&#xe608;</i>添加
			</button>
			<form style="display: inline-block">
				<div class="layui-input-inline">
					<select class="layui-select" name="selectKey" id="selectKey"></select>
				</div>
				<div class="layui-input-inline">
					<input type="hidden" name="select" id="select" value="<%=request.getAttribute("selectKey")%>">
					<input type="text" class="layui-input" name="keywords" id="keywords" value="${keywords}" placeholder="请输入要查询的员工姓名"> 
				</div>
				<button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach" name="op" value="">
					<i class="layui-icon">&#xe615;</i>
				</button>
			</form>
			<span class="x-right" style="line-height: 40px">共有数据：<span
				class="layui-badge">${pd.totalCount}</span> 条
			</span>
		</xblock>
		<table class="layui-table">
			<thead>
				<tr>
					<th><input type="checkbox" id="all" value=""></th>
					<th>员工编号</th>
					<th>员工姓名</th>
					<th>部门名</th>
					<th>学历</th>
					<th>性别</th>
					<th>身份证号</th>
					<th>入职时间</th>
					<th>家庭住址</th>
					<th>联系电话</th>
					<th>电子邮箱</th>
					<th>职位</th>
					<th>员工照片</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${pd == null}">
					<c:redirect url=" EmpServlet"></c:redirect>
				</c:if>
				<c:if test="${pd!=null }">
					<c:forEach items="${pd.data}" var="emp">
						<tr>
							<td><input type="checkbox" class="one" name="one" value="${emp.empNo}" ></td>
							<td>${emp.empNo}</td>
							<td>${emp.empName}</td>
							<td>${emp.deptName}</td>
							<td>${emp.empXl}</td>
							<td>${emp.empSex}</td>
							<td>${emp.empID}</td>
							<td>${emp.empTime}</td>
							<td>${emp.empAddress}</td>
							<td>${emp.empTel}</td>
							<td>${emp.empEmail}</td>
							<td>${emp.empJob}</td>
							<td><img src="${emp.empPic}" width="45px" height="42px"></td>
							<td class="td-manage">
								<a title="编辑" href="javascript:;" onclick="member_edit('编辑','EmpServlet?op=getEmp&empNo=${emp.empNo}&empPic=${emp.empPic}','4','800','800')" class="ml-5" style="text-decoration: none">
									<i class="layui-icon">&#xe642;</i>
								</a>
								<a title="删除" href="javascript:;"
									onclick="member_del(this,${emp.empNo})"
									style="text-decoration: none"> <i class="layui-icon">&#xe640;</i>
								</a>
							</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>
		<div id="pagediv" style="text-align: center"></div>
	</div>
	<script src="./js/x-layui.js" charset="utf-8"></script>
	<script src="js/jquery-2.0.3.js"></script>
	<script src="layui/layui.js" charset="utf-8"></script>
	
	<script>
		layui.use(['laypage', 'layer'], function(){
		  var laypage = layui.laypage
		  ,layer = layui.layer;
		  
		  //分页
		  laypage.render({
		    elem: 'pagediv'
		    ,count: ${pd.totalCount}
		 	,curr:${pd.page}
		 	,limit:${pd.pageSize}
		    ,layout: ['prev', 'page', 'next']
		    ,jump: function(obj,first){     
		      //首次不执行
		      if(!first){
		    	  location.href="EmpServlet?page="+obj.curr+"&keywords="+$("#keywords").val();
		      }
		    }
		  });
		});
		//复选框
		$(function(){
			$("#all").click(function(){
				$("input[class = one ]").prop("checked",this.checked);
			});
		})
		//批量删除
		function delAll() {
			var result = "";
			var count = 0;
			$(".one").each(function(){
				if($(this).is(':checked')){
					
					result += $(this).val()+",";
					count += 1;
				}else{}
			})
			layer.confirm('确认要删除吗？', {
				icon : 3,
				title : '提示信息'
			}, function(index) {
				$.ajax({
					type:"post",
					url:"EmpServlet",
					data:{
						r : result,
						op : "delAll"
					},
					success:function(data){
						if(data == "删除成功!"){
							layer.msg("删除"+count+"条成功",{icon:1,time:1000});
		                    setTimeout(function(){
		                        window.location.reload();
		                        var index = parent.layer.getFrameIndex(window.name);
		                        parent.layer.close(index);
		                    },1000);
		                    return false;
						}else{
							layer.msg(data,{icon:5,time:2000});
		                    return false;
						}
					},
					dataType:"json"
				});
				return false;
			});
		}
		/*用户-添加*/
		function member_add(title, url, w, h) {
			x_admin_show(title, url, w, h);
		}
		/*用户-查看*/
		function member_show(title, url, id, w, h) {
			x_admin_show(title, url, w, h);
		}

		// 用户-编辑
		function member_edit(title, url, id, w, h) {
			x_admin_show(title, url, w, h);
		}
		
		/*用户-删除*/
		function member_del(obj, id) {
			layer.confirm('确认要删除吗？', {
				icon : 3,
				title : '提示信息'
			}, function(index) {
				$.ajax({
					type : "post",
					url : "EmpServlet",
					data : {
						empNo : id,
						op : "del"
					},
					success:function(data){
						if(data == "删除成功"){
							layer.msg(data,{icon:1,time:1000});
		                    setTimeout(function(){
		                        window.location.reload();
		                        var index = parent.layer.getFrameIndex(window.name);
		                        parent.layer.close(index);
		                    },1000);
		                    return false;
						}else{
							layer.msg(data,{icon:5,time:2000});
		                    return false;
						}
				   },
				   dataType:"json"
			  });
				return false;
			});
		}
	</script>
	
	<script type="text/javascript">
		var selectArr = ["员工名","员工号","部门名","学历","性别"];
		var selectKey = $("#select").val();
		$(function(){
			if(selectKey != ""){
				$("#selectKey").append("<option value = "+selectKey+">"+selectKey+"</option>");
				$.each(selectArr,function(i,o){
					if( o != selectKey){
						$("#selectKey").append("<option value = "+o+">"+o+"</option>");
					}
				})
			}else{
				$.each(selectArr,function(i,o){
					$("#selectKey").append("<option value = "+o+">"+o+"</option>");
				})
			}
		})
	</script>
	
</body>
</html>